package xmmc.command;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import xmmc.Main;


import java.util.List;
import java.util.Objects;


public class Maincommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0) {
            sender.sendMessage("§e[DieMsgQG]§b");
            sender.sendMessage("* /dmqg st - 查看当前实体数量");
            sender.sendMessage("* /dmqg qk - 查看当前区块数量");
            sender.sendMessage("* /dmqg reload - 重载插件");
        }
        else if (Objects.equals(args[0], "st")) {
            List<Entity> entityList = Bukkit.getServer().getWorlds().get(0).getEntities();
            int entityCount = entityList.size();
            sender.sendMessage(""+entityCount);
        }
        else if (Objects.equals(args[0], "qk")) {
            int totalChunks = 0;
            for (World world : Bukkit.getWorlds()) {
                totalChunks += world.getLoadedChunks().length;
            }
            sender.sendMessage(""+totalChunks);
            return true;
        }
        else if (Objects.equals(args[0], "reload")) {
            Plugin config = Main.getProvidingPlugin(Main.class);
            config.reloadConfig();
            sender.sendMessage("§e[DieMsgQG]§b插件重载成功");
        }
        return false;
    }

}